<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>首页 </title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <link href="css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link href="css/materialdesignicons.min.css"  th:href="@{/css/materialdesignicons.min.css}" rel="stylesheet">
    <link href="css/style.min.css" th:href="@{/css/style.min.css}" rel="stylesheet"></head>

<body>
<div class="lyear-layout-web" id="mainContent">
    <div  th:if="${session.grade} eq 3">
        <div th:replace="~{main::rightbar}"></div>
    </div>
    <div  th:if="${session.grade} eq 1">
        <div th:replace="~{kfmain::kfrightbar}"></div>
    </div>
    <div  th:if="${session.grade} eq 2">
        <div th:replace="~{csmain::csrightbar}"></div>
    </div>
    <div th:replace="~{main::topbar}"></div>
    <div class="lyear-layout-container">

        <header class="lyear-layout-header" th:fragment="topbar">

            <nav class="navbar navbar-default">
                <div class="topbar">

                    <div class="topbar-left">
                        <div class="lyear-aside-toggler">
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                        </div>
                        <span class="navbar-page-title"> bug管理 </span>
                    </div>
                    <div th:replace="~{main::bar}"></div>


                </div>
            </nav>

        </header>

        <main class="lyear-layout-content">


            <div class="container-fluid">



                <div class="row">

                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header">
                                <h4>bug列表</h4>
                            </div>
                            <div class="card-body">

                                <table>
                                    <form onsubmit="return false" id="formAddtr" method="get">
                                        <td>
                                            <select class="form-control" id="example-select" name="grade" size="1">
                                                <option value="0">请选择</option>
                                                <option value="0">所有bug</option>
                                                <option value="2">指派给我</option>
                                            </select>
                                        </td>
                                        <td>&nbsp;&nbsp;</td>
                                        <td>
                                            <button class="btn btn-primary m-r-5" onclick="subForm()"><i class="mdi mdi-plus"></i>搜索</button>
                                        </td>
                                        <td>&nbsp;&nbsp;</td>

                                    </form>
                                </table>

                                <div class="table-responsive">
                                    <table class="table table-hover" >
                                        <thead>
                                        <tr>
                                            <th>bug名称</th>
                                            <th>bug描述</th>
                                            <th>bug等级</th>
                                            <th>创建日期</th>
                                            <th>结束日期</th>
                                            <th>bug状态</th>
                                            <th>上传者</th>
                                            <th>指派给</th>
                                            <th>查看详情</th>
                                            <th>确认</th>
                                            <th>解决</th>
                                        </tr>
                                        </thead>
                                        <tbody id="boby">
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>

<!--图表插件-->
<script type="text/javascript" src="js/Chart.js"></script>

<script type="text/javascript">
    //别忘了导入该用的js文件
    subForm();
    function subForm() {
        var checkValue=$("#example-select").val();
        console.log(checkValue)
        var list = getuserlist();
        // console.log(list)
        $.ajax({

            url: '/kfbuglist/'+checkValue, //请求的url
            type: 'get', //请求的方式
            //form表单里要提交的内容，里面的input等写上name就会提交，这是序列化
            cache : false,
            async : true,
            error:function (data) {
                alert('请求失败');
            },
            success:function (data) {
                console.log(data)
                var str1 = "";
                //清空table中的html
                $("#boby").html("");
                var status
                for(var i = 0;i<data.length;i++){
                    if(data[i].status==1)
                    {
                        status="被创建"
                    }else if(data[i].status==2)
                    {
                        status="已确认"
                    }else if(data[i].status==3)
                    {
                        status="已完成"
                    }else
                    {
                        status="已关闭"
                    }
                    if(data[i].enddate==null)
                    {
                        data[i].enddate="未结束"
                    }
                    var upid=data[i].upid;
                    var downid=data[i].downid;
                    console.log(downid)
                    str1 = "<tr>" +
                        "<td>"+data[i].bugname + "</td>" +
                        "<td>"+data[i].bugmiaoshu + "</td>" +
                        "<td>"+data[i].grade + "</td>" +
                        "<td>"+data[i].newdate + "</td>" +
                        "<td>"+data[i].enddate + "</td>" +
                        "<td>"+status + "</td>" +
                        "<td>"+list[upid] + "</td>" +
                        "<td>"+list[downid] + "</td>" +
                        "<td>"+"<a href='/chakanbug?id="+data[i].id+"'" +"style=' height: 21px;\n" +
                        "            line-height: 21px;\n" +
                        "            padding: 0 11px;\n" +
                        "            background-color: #33cabb;\n" +
                        "           border-color: #33cabb;\n" +
                        "            color: #fff!important;\n" +
                        "            border-radius: 3px;\n" +
                        "            display: inline-block;\n" +
                        "            text-decoration: none;\n" +
                        "            font-size: 12px;\n" +
                        "            outline: none;'>查看图片</a>"+"</td>";
                    if(list.userid!=data[i].downid)
                    {
                        str1=str1+"<td>"+"没有权限操作" + "</td>";
                    } else if(data[i].status==1)
                    {
                        str1=str1+ "<td>"+"<a onclick='qrbug("+data[i].id+")'"+"style=' height: 21px;\n" +
                            "            line-height: 21px;\n" +
                            "            padding: 0 11px;\n" +
                            "            background-color: #33cabb;\n" +
                            "           border-color: #33cabb;\n" +
                            "            color: #fff!important;\n" +
                            "            border-radius: 3px;\n" +
                            "            display: inline-block;\n" +
                            "            text-decoration: none;\n" +
                            "            font-size: 12px;\n" +
                            "            outline: none;'>确认</a>"+"</td>";
                    }else {
                        str1=str1+"<td>"+"已确认" + "</td>" ;
                    }

                    if(list.userid!=data[i].downid)
                    {
                        str1=str1+"<td>"+"没有权限操作" + "</td>" +"</tr>";
                    }else if(data[i].status==2)
                    {
                        str1=str1+"<td>"+"<a onclick='wcbug("+data[i].id+")'"+"style=' height: 21px;\n" +
                            "            line-height: 21px;\n" +
                            "            padding: 0 11px;\n" +
                            "            background-color: #33cabb;\n" +
                            "           border-color: #33cabb;\n" +
                            "            color: #fff!important;\n" +
                            "            border-radius: 3px;\n" +
                            "            display: inline-block;\n" +
                            "            text-decoration: none;\n" +
                            "            font-size: 12px;\n" +
                            "            outline: none;'>确认</a>"+"</td>";
                    }
                    else
                    {
                        str1=str1+"<td>"+"未确认或已关闭" + "</td>" +"</tr>";
                    }

                    $("#boby").append(str1);
                }
            }
        });
    }
    function qrbug(id){

        $.ajax({
            type:'get',
            url:'/qrbug/'+id,
            // data:user,
            //contentType:'application/json;charset=UTF-8',

            async : true,
            // global:false,
            success:function(json){
                alert('确认成功');
                subForm();
            },
            error: function (data) {
                alert('确认失败');
            },
        });


    }
    function wcbug(id){

        $.ajax({
            type:'get',
            url:'/wcbug/'+id,
            // data:user,
            //contentType:'application/json;charset=UTF-8',

            async : true,
            // global:false,
            success:function(json){
                alert('确认成功');
                subForm();
            },
            error: function (data) {
                alert('确认失败');
            },
        });


    }
    function getuserlist(){
        var a=[];
        $.ajax({
            type:'get',
            url:'/getuserlist',
            // data:user,
            //contentType:'application/json;charset=UTF-8',

            async : false,
            // global:false,
            success:function(json){
                console.log(json)
                a = json;
            },

            error: function (data) {

            },
        });
        console.log(a)

        return a;

    }

</script>
</body>

</html>